import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:tappay_charge/models/tappay_card_type.dart';
import 'package:tappay_charge/models/tappay_prime.dart';
import 'package:tappay_charge/models/tappay_sdk_common_result.dart';
import 'package:tappay_charge/models/tappay_cart_item.dart';

import 'tappay_charge_method_channel.dart';

abstract class TappayChargePlatform extends PlatformInterface {
  /// Constructs a TappayChargePlatform.
  TappayChargePlatform() : super(token: _token);

  static final Object _token = Object();

  static TappayChargePlatform _instance = MethodChannelTappayCharge();

  /// The default instance of [TappayChargePlatform] to use.
  ///
  /// Defaults to [MethodChannelTappayCharge].
  static TappayChargePlatform get instance => _instance;

  /// Platform-specific implementations should set this with their own
  /// platform-specific class that extends [TappayChargePlatform] when
  /// they register themselves.
  static set instance(TappayChargePlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  Future<String?> getPlatformVersion();

  /// 初始化Tappay SDK
  Future<TappaySdkCommonResult> initTappay({
    required int appId,
    required String appKey,
    required bool isSandBox
  });

  /// 驗證卡號是否可用
  ///
  /// [cardNumber]: 卡號
  /// [dueMonth]: 過期月份
  /// [dueYear]: 過期年份
  /// [ccv]: 驗證值
  Future<bool> validateCard({
    required String cardNumber,
    required String dueMonth,
    required String dueYear,
    required String ccv,
  });

  /// 獲取卡的Prime
  ///
  /// [cardNumber]: 卡號
  /// [dueMonth]: 過期月份
  /// [dueYear]: 過期年份
  /// [ccv]: 驗證值
  Future<TappayPrime> getCardPrime({
    required String cardNumber,
    required String dueMonth,
    required String dueYear,
    required String ccv,
  });

  /// 初始化Apple Pay, 發起支付前需要調用該方法
  ///
  /// [merchantId] 商店標識
  /// [merchantName] 需要顯示的商家名稱
  /// [currencyCode] 貨幣代碼，default: TWD
  /// [countryCode] 國家代碼，default: TW
  /// [supportedCardTypes] 支持的信用卡類型
  ///     默認支持[TappayCardType.visa]、[TappayCardType.masterCard]、[TappayCardType.amex]和[TappayCardType.jcb]
  Future<TappaySdkCommonResult> initApplePay({
    required String merchantId,
    required String merchantName,
    String? currencyCode,
    String? countryCode,
    List<TappayCardType>? supportedCardTypes,
  });

  /// 發起Apple Pay
  ///
  /// [isAmountPending] 決定是否使用延後授權，預設為false
  /// [isShowTotalAmount] 決定總金額欄位是否顯示總金額或金額待處理，預設為true
  /// [paymentItems] 購物車交易項次
  Future<TappayPrime> startApplePay({
    bool isAmountPending = false,
    bool isShowTotalAmount = true,
    required List<TappayCartItem> cartItems,
  });

  /// 上传Apple Pay支付結果
  ///
  /// 当发送prime到服务器得到验证后，上传结果到Tappay
  ///
  /// [result] 交易的结果
  Future<TappaySdkCommonResult> showApplePayResult({required bool result});

  /// 检测Line Pay是否可用
  Future<bool> isLinePayAvailable();

  /// 獲取Line Pay Prime
  ///
  /// [returnUrl] 回跳至App的自定義Scheme
  Future<TappayPrime> getLinePayPrime({required String returnUrl});

  /// 跳轉至Line Pay進行支付
  ///
  /// [paymentUrl]跳轉到Line Pay的付款頁面地址
  Future<TappayPrime> redirectLinePay({required String paymentUrl});

  /// 检测Easy Wallet是否可用
  Future<bool> isEasyWalletAvailable();

  /// 獲取Easy Wallet Prime
  ///
  /// [returnUrl] 回跳至App的自定義Universal Link
  Future<TappayPrime> getEasyWalletPrime({required String returnUrl});

  /// 跳轉至Easy Wallet進行支付
  ///
  /// [paymentUrl]跳轉到Easy Wallet的付款頁面地址
  Future<TappayPrime> redirectEasyWallet({required String paymentUrl});
}
